#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <cassert>

int const maxn = 4000;
long long a[maxn], b[maxn];
long long s1, s2;
long long ans;

template <class T>
T myabs(T const & a) { return a >= 0 ? a : -a; }

int main()
{
	int n, m;
	std::cin >> n;
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	std::cin >> m;
	for (int i = 1; i <= m; i++) std::cin >> b[i];
	{
		std::ifstream f1("bfdiff.out1");
		f1 >> s1;
		for (int i = 1, x; i <= n; i++) {
			std::cin >> x;
			ans += myabs(a[i] - b[x]);
		}
	}
	{
		std::ifstream f2("bfdiff.out2");
		f2 >> s2;
	}
	if (s1 != s2) std::cout << "no, ans not correct\n";
	else if (s1 != ans) std::cout << "no, output not correct\n";
}

